package com.maniu.h265_client;

import android.app.Activity;
import android.os.Bundle;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Button;


import java.io.File;

import androidx.annotation.NonNull;

public class MainActivityLocal extends Activity {

    private static final String TAG = "David";
    Surface surface;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
        surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(@NonNull SurfaceHolder holder) {
                surface = holder.getSurface();
                btn.setText("sruface ready");
            }

            @Override
            public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {

            }

            @Override
            public void surfaceDestroyed(@NonNull SurfaceHolder holder) {

            }
        });

        btn= (Button) findViewById(R.id.btn);

        btn.setOnClickListener(v -> {
            if (surface!=null){
                doDecodeAction();
            }
        });
    }

    private void doDecodeAction() {
        Thread thread=new VideoThread(surface,new File("/sdcard/play.mp4"));
        thread.start();
    }
}